#include "cp56time2a.h"
#include <stdio.h>

static st_cp56time2a *Cp56time2a;

static int drv_write(st_cp56time2a *Cp56time2a)
{
    Cp56time2a->Compts.year = 21;
    Cp56time2a->Compts.month = 9;
    Cp56time2a->Compts.mday = 1;
    Cp56time2a->Compts.hour = 10;
    Cp56time2a->Compts.min = 31;
    Cp56time2a->Compts.msec = 41443;

    printf("\n\t Cp56time2a  :  %llX \n\r", Cp56time2a->Time);
    return 0;
}

static int drv_read(st_cp56time2a *Cp56time2a)
{
    Cp56time2a->Time = 0x1509010A1FA1E3;

    printf("\n\t Year  :  %d \n\r", Cp56time2a->Compts.year);
    printf("\n\t month :  %d \n\r", Cp56time2a->Compts.month);
    printf("\n\t mday  :  %d \n\r", Cp56time2a->Compts.mday);
    printf("\n\t wday  :  %d \n\r", Cp56time2a->Compts.wday);
    printf("\n\t hour  :  %d \n\r", Cp56time2a->Compts.hour);
    printf("\n\t min   :  %d \n\r", Cp56time2a->Compts.min);
    printf("\n\t msec  :  %d \n\r", Cp56time2a->Compts.msec);
}

static void drv_open(st_cp56time2a *Cp56time2a)
{
    Cp56time2a->Time = 0;
}

static void drv_close(st_cp56time2a *Cp56time2a)
{
    Cp56time2a->Time = 0;
}

struct cp56time2a
{
    int (*open)(st_cp56time2a *Cp56time2a);
    int (*read)(st_cp56time2a *Cp56time2a);
    int (*write)(st_cp56time2a *Cp56time2a);
    int (*close)(st_cp56time2a *Cp56time2a);
}Handle = {
    .open = drv_open,
    .read = drv_read,
    .write = drv_write,
    .close = drv_close
};

struct cp56time2a *get_ops(void)
{
    return &Handle;
}

void set_time(struct cp56time2a *Handle)
{
    Handle->write(Handle);
}

void get_time(struct cp56time2a *Handle)
{
    Handle->read(Handle);
}